﻿using kelianxi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kelianxi.DAL
{
    public class UserDAL
    {
        public UserDAL(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <param name="name">管理员姓名</param>
        /// <param name="pwd">管理员密码</param>
        /// <returns></returns>
        public User Login(string name,string pwd)
        {
            try
            {
                //var count = Context.Users.Where(x => x.name == name).Count();
                //if(count==0)
                //{
                //    return -1;
                //}
                //else
                //{
                //    var c=Context.Users.Where(x=>x.name == name && x.pwd==pwd).FirstOrDefault();
                //    return c;
                //}


                var e=Context.Users.FirstOrDefault(x=>x.name == name);
                if (e == null)
                {
                    return new User { Id = -1 };
                }
                else
                {
                    if (e.pwd != pwd)
                    {
                        return new User { Id = -2 };
                    }
                }
                return e;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        public User User { get; set; }



    }
}
